<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <father-page></father-page>
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp();
    // 外部定义 公共混入对象
    const mixin = {
      data(){
        return {
          msg: '这是混入对象中的数据'
        }
      },
      methods: {
        changeMsg(){
          this.msg = '值改变了'
        }
      },
      watch: {
        msg(newVal) {
          console.log('msg改变了');
        }
      }
    }
    const FatherPage = {
      template: `
        <div>
          <h2>这是组件1</h2>  
          {{msg}}
          <button @click="changeMsg">按钮</button>
        </div>
      `,
      data(){
        return {
          msg: '这是组件自己的数据'
        }
      },
      mixins: [mixin]
    }
    app.component('FatherPage', FatherPage)

    app.mount('#app')
  </script>
</body>
</html>